import Vue from 'vue'
import Vuex from 'vuex'

Vue.use(Vuex)

export default new Vuex.Store({
  state: {
    //登录框的状态
    isOpenlogin: false,
    isLogin: false,
    modal: {
      isAlert: false,
      isMsg: '',
      icon: ''
    },
    //页面切换
    yemianShow: true
  },
  getters: {
  },
  mutations: {
    chageisOpenLogin(state, payload) {
      state.isOpenlogin = payload
    },
    chageAlert(state, payload) {
      state.modal.isAlert = payload
    },
    closeAlert(state) {
      state.modal.isAlert = false
    },
    chageAlertmsg(state, payload) {
      state.modal.isAlert = payload.isAlert
      state.modal.isMsg = payload.isMsg
      state.modal.icon = payload.icon
      switch (payload.icon) {
        case 'info':
          state.modal.icon = "icon-toast-jinggao";
          break;
        case 'success':
          state.modal.icon = "icon-toast_chenggong";
          break;
        case 'danger':
          state.modal.icon = "icon-toast-shibai_huaban";
          break;
        case 'loading':
          state.modal.icon = "icon-loading";
          break;
        default:
          state.toast.icon = "icon-toast-jinggao";
          break;
      }
    },
    chageisLogin(state, payload) {
      state.isLogin = payload
    },

    //界面切换
    chageYemianShow(state, payload) {
      state.yemianShow = payload
    }
  },
  actions: {
    Asyncalert({ commit }, payload) {
      commit('chageAlert', payload);
      setTimeout(() => {
        commit('closeAlert')
      }, 1000)
    }
  },
  modules: {
  }
})
